/**
 * 
 *  @project Air Traff Monitor
 * 
 *  @author M.Emre ATASEVER <m.emre.atas@gmail.com>
 *  @author M.Burak ALKAN <mburakalkan@gmail.com>
 *  @author H.Burak KARAMIK <bkaramik@gmail.com>
 *
 *	`Air Traffic Monitor' is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License
 *	along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "netview.h"

#include <QHeaderView>
#include <QApplication>

QKismetNetView::QKismetNetView(QKismetSocket *sock) : QKismetTreeView(new NetworkModel(sock))
{
	socket = sock;

	connect(this,SIGNAL(setOption(QString,bool)),socket,SLOT(SetNetOption(QString,bool)));	
	connect(this,SIGNAL(setOption(QString,bool)),socket,SLOT(SetClientOption(QString,bool)));	
	headMenu = new QMenu();
	createMenus();
	sock->SetNetOption("wep",true);
	sock->SetNetOption("manufscore",true);
	sock->SetClientOption("wep",true);
	sock->SetClientOption("manufscore",true);

}
QKismetNetView::~QKismetNetView()
{
	SaveSettings();
	delete headMenu;
}
void QKismetNetView::createMenus()
{
	QMenu *m = appendMenu("Network info",socket->net.getNames(),socket->net.getCaps(),headMenu,0,23);
	QList<QAction*> acts = m->actions();



	m = appendMenu("Turbocell info",socket->net.getNames(),socket->net.getCaps(),m,23,26);
	acts += m->actions();
	
	m = appendMenu("Geolocalization",socket->net.getNames(),socket->net.getCaps(),headMenu,26,41);
	acts += m->actions();

	m = appendMenu("Packet info",socket->net.getNames(),socket->net.getCaps(),headMenu,41,46);
	acts += m->actions();

	m = appendMenu("Signal info",socket->net.getNames(),socket->net.getCaps(),headMenu,46,52);
	acts += m->actions();
	acts[0]->setEnabled(false);

	QHeaderView *head = header();

	QString ss("NetviewOptions");
	RestoreSettings(ss,acts);
	head->setContextMenuPolicy(Qt::CustomContextMenu);
	connect(head,SIGNAL(customContextMenuRequested(const QPoint&)),this,SLOT(showHeadMenu(const QPoint&)));
}
void QKismetNetView::SaveSettings()
{
	QString ss("NetviewOptions");
	WriteSettings(ss);
}

